package com.ruoyi.system.domain.deviceAlarm;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class DeviceAlarm {
    private InfoAlarm info;
    private List<Spo2Alarm> alarmSpo2s;
    private List<BpAlarm> alarmBps;
    private List<HrAlarm> alarmHrs;

    public DeviceAlarm(JSONObject data){
        alarmSpo2s=new ArrayList<>();
        alarmBps=new ArrayList<>();
        alarmHrs=new ArrayList<>();
        //info =new InfoAlarm((JSONObject) data.get("alarmInfo"));
        JSONArray spo2sJsonArray=(JSONArray)data.get("alarmSpo2s");
        if(spo2sJsonArray!=null){
            for(Object one : spo2sJsonArray){
                Spo2Alarm spo2Alarm=new Spo2Alarm((JSONObject) one);
                alarmSpo2s.add(spo2Alarm);
            }
        }
        JSONArray bpsJsonArray=(JSONArray)data.get("alarmBps");
        if (bpsJsonArray!=null) {
            for (Object one : bpsJsonArray) {
                BpAlarm bpAlarm = new BpAlarm((JSONObject) one);
                alarmBps.add(bpAlarm);
            }
        }
        JSONArray hrsJsonArray=(JSONArray)data.get("alarmHrs");
        if ( hrsJsonArray!=null) {
            for (Object one : hrsJsonArray) {
                HrAlarm hrAlarm = new HrAlarm((JSONObject) one);
                alarmHrs.add(hrAlarm);
            }
        }
    }
}
